package com.eric.ztea.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Log;
import com.eric.ztea.comm.HttpUtil;

/**
 * @author Javen
 * 2016年4月3日
 */
public class SMSUtils {
	static Log logger = Log.getLog(SMSUtils.class);
	/* 短信配置资源 */
	private static final Prop prop = PropKit.use("sms.properties");
	private final static String SMS_URL="https://api.miaodiyun.com/20150822/industrySMS/sendSMS";
	/* 短信配置详情 */
	private static final String SMS_NAME 					= prop.get("name");
	private static final String SMS_PWD 					= prop.get("pwd");
	private static final String SMS_CONTENT_REGISTER_CODE 	= prop.get("content_register_code");
	private static final String SMS_CONTENT_FORGET_CODE 	= prop.get("content_forget_code");
	private static final String CONTENT_REGISTER_NOTIFY 	= prop.get("content_register_notify");
	private static final String CONTENT_ORDER_NOTIFY 	    = prop.get("content_order_notify");
	private static final String SMS_TYPE 					= prop.get("type");
	
	public enum SendSMSType {
		REGISTER,FORGET,ORDER_NOTIFY,REGISTER_NOTIFY
	}
	/**
	 * 发送短信验证码
	 * @param mobile
	 * @param code
	 * @param sendSMSType
	 * @return
	 */
	public static int SMSCode(String mobile,String code,String nickName,String courseName,String uesrMobile,String courseCount,SendSMSType sendSMSType){
		if (true)
		{
			return 0;
		}
		int res_code = -9;
		try {
			String queryPara = "accountSid=7886505b6e5444dd97acc30ce2a336e6&to=13991278945"
					+ "&smsContent=【正通充电】您的验证码为"
					+ code
					+ "，请于2分钟内正确输入，如非本人操作，请忽略此短信。"
					+ HttpUtil.createCommonParam();
			System.out.println(queryPara);
			String result = HttpKit.post(SMS_URL, queryPara);
			logger.info("发送短信返回结果："+result);

			JSONObject jsonObject=JSONObject.parseObject(result);
			String respCode = jsonObject.getString("respCode");
			res_code = Integer.parseInt(respCode);
		} catch (Exception e) {
			res_code=-10;
			logger.error("send sms to "+mobile+" error:"+e.getMessage());
		}
		return res_code;
	}
}
